/* 
 * File:   pager.h
 * Author: Chen Liu
 *
 * Created on September 21, 2012, 12:40 PM
 */

#include <stdlib.h>
#include <vector>
#ifndef INT_MAX 
#define INT_MAX	 ((int)(~0U>>1))
#endif

using namespace std;
enum AlgType{eFIFO, eRandom, eLRU, eLFU, eSecondChance, eOptimalPageReplacement};

typedef struct {
    int pageNum;
    int mark;
} PageRecord;

class Pager {
    public:
        Pager();
        void Init(AlgType Alg, int NumFrames);
        bool AccessPage(int PageNum);
        int GetPageFaults();
        void SetPageRefs(const vector<int> &pageRefs);
        void SetPageNum(int pageNum);
    private:
        int pageNum;
        vector<int> pageRefs;
        AlgType algType;
        int frame_num;
        int pageFaults;
        vector<PageRecord> frames;
        int currentPosition;
        vector<int> pageMark;
        vector<int> freeFrames;
};

